package com.edata.bigdata.viewmain;

import com.edata.bigdata.basic.Manager;
import com.edata.bigdata.entity.Workspace;
import com.edata.bigdata.spark.HdfsConnector;
import com.edata.bigdata.spark.HdfsWriter;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.RowFactory;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

public class HdfsWrite {

    public static void main(String[] args) {
        Manager manager = new Manager();
        manager.APPNAME = "HDFSWriteTesting";
        manager.MASTER = "local[*]";
        manager.createSparkSession();

        HdfsConnector hdfsConnector = new HdfsConnector();
        hdfsConnector.ENTRYPOINT = "172.16.11.97:8082";

        HdfsWriter hdfsWriter = new HdfsWriter(manager.SPARKSESSION);
        hdfsWriter.hdfsConnector = hdfsConnector;


        String workspaceId1 = UUID.randomUUID().toString();
        String workspaceId2 = UUID.randomUUID().toString();
        String workspaceId3 = UUID.randomUUID().toString();
        List<Row> datas = Arrays.asList(
                RowFactory.create(workspaceId1, "terraria_1", "/app/datas/" + workspaceId1),
                RowFactory.create(workspaceId2, "terraria_2", "/app/datas/" + workspaceId2),
                RowFactory.create(workspaceId3, "terraria_3", "/app/datas/" + workspaceId3)
        );
        hdfsWriter.write(datas, "/testing/workspace", "overwrite", Workspace.class);
        manager.stop();

    }

}
